package com.example.hzly.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.hzly.entity.StoryLike;
import com.example.hzly.mapper.StoryLikeMapper;
import com.example.hzly.service.StoryLikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StoryLikeServiceImpl extends ServiceImpl<StoryLikeMapper, StoryLike> implements StoryLikeService {
    @Autowired
    private StoryLikeMapper storyLikeMapper;

    @Override
    public boolean addLike(Long userId, Long storyId) {
        if (isLiked(userId, storyId)) return false;
        StoryLike like = new StoryLike();
        like.setUserId(userId);
        like.setStoryId(storyId);
        return save(like);
    }

    @Override
    public boolean removeLike(Long userId, Long storyId) {
        return lambdaUpdate().eq(StoryLike::getUserId, userId).eq(StoryLike::getStoryId, storyId).remove();
    }

    @Override
    public boolean isLiked(Long userId, Long storyId) {
        return storyLikeMapper.findByUserAndStory(userId, storyId) != null;
    }
} 